package com.xiaojf.xsso.sample.web.controller;

import com.xiaojf.xsso.common.constant.SsoConstant;
import com.xiaojf.xsso.common.model.CommonResult;
import com.xiaojf.xsso.common.model.SsoUser;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 首页
 *
 * @author Ade.Xiao 2017-08-01 21:39:47
 */
@Controller
public class IndexController {
    /**
     * 测试接口， 页面重定向
     *
     * @param model
     * @param request
     * @return {@link String}
     * @author Ade.Xiao 2021-03-12 09:48:38
     */
    @RequestMapping("/")
    public String index(Model model, HttpServletRequest request) {

        SsoUser ssoUser = (SsoUser) request.getAttribute(SsoConstant.SSO_USER);
        model.addAttribute("ssoUser", ssoUser);
        return "index";
    }

    /**
     * 测试接口， 返回json字符串
     *
     * @param model
     * @param request
     * @return {@link CommonResult< SsoUser>}
     * @author Ade.Xiao 2021-03-12 09:48:48
     */
    @RequestMapping("/json")
    @ResponseBody
    public CommonResult<SsoUser> json(Model model, HttpServletRequest request) {
        SsoUser ssoUser = (SsoUser) request.getAttribute(SsoConstant.SSO_USER);
        return new CommonResult(ssoUser);
    }

}